var commentGoods = {//评价商品 

	pageInfo:{//分页信息
		pageNo:1, //请求页
        lastPage:1, //最大页面
        pageSize:6,//每页个数
        currPage:1//当前页
	},
	
	goodsId:null,
	recommendType:null,
	 
	 init:function(goodsId){
	    commentGoods.goodsId = goodsId; 
	    commentGoods.clearComment();
	    //commentGoods.list();
	    
	 },
	 
	 
	//列出 物品评价  
	list:function(){
		var dataStr ='goodsId='+commentGoods.goodsId;
		dataStr+="&currPage="+commentGoods.pageInfo.pageNo;//分页
		 $.ajax({
			   type: "POST",
			   url: "/goods/comment-list-a.jspa",
			   data: dataStr,
			   dataType : 'json',
			   success: function(json){//评论或者回复
			        if(json!=null&&json.commentVOLst!=null){
				        if(json.commentVOLst.length>0){
				   			commentGoods.showAllList(json.commentVOLst);
				   		}
			        } 
			   }
		  })
		
	},	
	//显示所有的评论 
	showAllList:function(commentList){
		var result = '';
		for(var i = 0 ;i< commentList.length;i++){
		  result+= commentGoods.showSingle(commentList[i]);
		}
		document.getElementById('pinglun1Content').innerHTML=result;
		//return result;
	},
	
	showSingle:function(comment ){//显示单个
		var str = '';
		str+='<div class="pllist">' 
	        +'<table width="750" border="0" cellspacing="0" cellpadding="0" style="table-layout: fixed;WORD-BREAK: break-all;WORD-WRAP: break-word;">' 
	         +' <tr>' 
	          +'  <td width="60" rowspan="3" align="left" valign="top"><img src="images/face.gif" width="48" height="48"></td>' ;
	    str+= commentGoods.show_nameAndMark(comment);
	    str+= '  </tr>' 
	         +' <tr>' 
	         +'   <td align="left" valign="middle">'+comment.comment+'</td>' 
	        +'  </tr>' 
	        +'  <tr>' 
	         +'   <td height="25" align="left"><span class="snf8">2010 来自上海</span></td>' 
	        +'  </tr>' 
	        +'</table>' ;
	    str+= commentGoods.show_replayContend(comment);
	    str+='</div>' ;
		return str; 
	},
	
	show_nameAndMark:function(comment){//显示名称和评分
		var result = '<td width="690" height="25" align="left" valign="middle">'+comment.nickName+'&nbsp;';
		if(comment.mark !=null){
		  result+='  <IMG align="absMiddle" src="http://www.yesmywine.comother/.com/inc/head/Platinum.gif">&nbsp;说：<img src="other/.com/wineshow/shou'+commentGoods.getMarkImg(comment.mark)+'.gif" align="absmiddle">';
		}
		result+='</td>' ;
		return result ;
	},
	
	getMarkImg:function(mark){
		if(mark==2){
			return 3;
		}
		if(mark == 1){
			return 1;
		}
		if(mark == 3){
			return 2;
		}
	},
	
	show_replayContend:function(comment){//显示回复内容 
		var result =  '';
		if(comment.replayContend!=""){
		     result += '<table width="750" border="0" cellspacing="0" cellpadding="0" style="table-layout: fixed;WORD-BREAK: break-all;WORD-WRAP: break-word;">' 
		         +'  <tr>' 
		         +'   <td width="60" rowspan="2" align="left" valign="top">&nbsp;</td>'
		         +'    <td width="690" height="25" align="left" valign="middle"><a class="snf4">Yesmywine 回复</a></td>' 
		         +' </tr>'   
		         +' <tr>' 
		         +'   <td align="left" valign="middle"><span class="snf10">'+comment.replayContend+'</span></td>' 
		         +' </tr>' 
		         +' </table>' ;
		}
		return  result;
	},
	//发表评论 
	submitRecommend:function(subffix){
		var scoreId = "score";
		var commentId = "#comment";
		if (subffix) {
			scoreId += subffix;
			commentId += subffix
		}

		var comment = $.trim($(commentId).val());
	  try{
		var scoreValue = $(":radio:checked").val();
		
		//alert(scoreValue);
		}catch(e){
		  alert(e.message);
		}
		
		if(scoreValue == undefined|| scoreValue==""){
			alert("请给商品评分！");
			return;
		} 
		if(comment == ""){
			alert("评论不能为空！");
			$("#comment"+subffix)[0].focus();
			return;
		}else{
			if((comment.length) > 240){
				alert("对不起，评论最多只能有240个字符！");
				$("#comment"+subffix)[0].focus();
				return;
			}
		}	
		var url = document.URL;
		var lastIndex = url.lastIndexOf(".html");
		if(lastIndex!=-1){
		  url = url.substring(0,lastIndex+5);
		}
		//处理%引起的tomcat异常
		comment=encodeURI(comment);
		$.ajax({
		   type: "POST",
		   url: "/goods/recommend-goods.jspa",
		   data: "goodsId="+commentGoods.goodsId+"&score="+scoreValue+"&recommend="+comment+"&URL="+url,
		   dataType:'json',
		   success: function(json){
		   	    if(json.info.flag == -1){
		   	    	if(json.info.msg=='no login'){//没有登陆 
		   	    		if(confirm("请先登录!")){
			   	    		showLoginDiv('commentGoods.submitRecommend('+subffix+')');
		   	    		}
		   	    	}else{
		   	    		alert(json.info.msg);
		   	    	}
		   	    }else{
		   	        alert(json.info.msg);
		   	   		commentGoods.clearComment(subffix);
		   	   		//window.location.reload();
		   	   		//commentGoods.list();
		   	    }
		   }
		})
		  
	},
	//清理空输入内容 
	clearComment:function(subffix){
		try{
			radioDoNotChecked("score");
			$("#comment3").val("");
			$("#comment4").val("");
			$("#comment5").val("");
			$("#comment6").val("");
			$("#comment").val("");			
   	    	//刷新显示
   	    	goodsDetail.getGoodsReview(commentGoods.goodsId,1,1,subffix);
		}catch(e){
			//alert(e.message);
		}
	}
	
}